# @Time : 2020/6/28 17:05
# @Author : Fioman 
# @Phone : 13149920693
"""
可选参数可以具有默认值,这是Python函数定义的一个很棒的特性,这样我们的API在金华的同时能够保证向后兼容.
然而,我们应该笔辩使用可变的对象作为参数的默认值.
"""

class HauntedBus(object):
    """备受幽灵乘客折磨的校车"""
    def __init__(self,passengers = []):
        self.passengers = passengers

    def pick(self,name):
        self.passengers.append(name)

    def drop(self,name):
        self.passengers.remove(name)

if __name__ == '__main__':
    bus1 = HauntedBus(["Alice","Bill"])
    print("bus1.passengers = {}".format(bus1.passengers))
    bus1.pick("Chrlie")
    bus1.drop("Alice")
    print("bus1.passengers = {}".format(bus1.passengers))

    bus2 = HauntedBus()
    bus2.pick("Carrie")
    print("bus2.passengers = {}".format(bus2.passengers))
    bus3 = HauntedBus()
    print("bus3.passengers = {}".format(bus3.passengers))

    bus3.pick("Dave")
    print("bus2.passengers = {}".format(bus2.passengers))

    print(bus2.passengers == bus3.passengers)
    print("bus1.passengers = {}".format(bus1.passengers))

    # 没有指定初始乘客的 HauntedBus 实例会共享同一个乘客列表.
